/**
 * Project Name:rx-java
 * File Name:FilterDemo.java
 * Package Name:top.xiaocao.rx.java.filter.function
 * Date:2024年2月13日下午4:05:56
 * Copyright (c) 2024, zhengchong.wan@minicore.com.hk All Rights Reserved.
 *
*/

package top.xiaocao.rx.java.filter.function;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Predicate;

/**
 * @className:FilterDemo 
 * @comment: 注释信息 
 * @date:     2024年2月13日 下午4:05:56 
 * @author   zhengchong.wan
 * @since    V1.0.0	 
 */
public class FilterDemo {

	public static void main(String[] args) {
		Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9).filter(new Predicate<Integer>() {
			@Override
			public boolean test(Integer integer) throws Exception {
				//条件：能否被2整除
				return integer % 2 == 0;
			}
		}).subscribe(new Observer<Integer>() {
			@Override
			public void onSubscribe(Disposable d) {
				System.out.println("filter：onSubscribe == 订阅");
			}

			@Override
			public void onNext(Integer integer) {
				System.out.println("filter：apply == 事件" + integer);
			}

			@Override
			public void onError(Throwable e) {
				System.out.println("filter：onError == " + e.getMessage());
			}

			@Override
			public void onComplete() {
				System.out.println("filter：onComplete == ");
			}
		});
	}

}
